﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using Entities;
using Datalayer;

namespace QLHoNgheo
{
    public partial class frm_BaoCao_search : Form
    {
        public frm_BaoCao_search()
        {
            InitializeComponent();
        }
        IQueryMgr iq;
        private void bt_search_Click(object sender, EventArgs e)
        {
            decimal _Deci_search = decimal.Parse(txt_search.Text);
            iq = QueryMgr.GetDbInstance();
            List<HoNgheo> ls = new List<HoNgheo>();
            if (lk_quan.EditValue != null)
            {
                int id = int.Parse(lk_quan.EditValue.ToString());
                ls = iq.HN_GetHoNgheoByQuanID(id);
                if (lk_phuong.EditValue != null)
                {
                    int idp = int.Parse(lk_phuong.EditValue.ToString());
                    ls = iq.HN_GetHoNgheoByPhuongID(idp);
                }
            }
            else
            {
                ls = iq.HN_GetAllHoNgheo();
            }
            gridControl1.DataSource = cl_EditAll1Form1.Create_dt(ls,_Deci_search);
        }

        void load_lk()
        {
            cl_Lookupedit.Lucb_Quanhuyen(ref lk_quan);
        }

        private void lk_quan_EditValueChanged(object sender, EventArgs e)
        {
            int id = int.Parse(lk_quan.EditValue.ToString());
            iq = QueryMgr.GetDbInstance();
            List<HoNgheo> ls = iq.HN_GetHoNgheoByQuanID(id);

            gridControl1.DataSource = cl_EditAll1Form1.Create_dt(ls);
            cl_Lookupedit.lucb_PhuongXa(ref lk_phuong, id);
        }

        private void lk_phuong_EditValueChanged(object sender, EventArgs e)
        {
            iq = QueryMgr.GetDbInstance();
            int id = int.Parse(lk_phuong.EditValue.ToString());
            List<HoNgheo> ls = iq.HN_GetHoNgheoByPhuongID(id);

            gridControl1.DataSource = cl_EditAll1Form1.Create_dt(ls);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            DataRow r;
            DevExpress.Utils.WaitDialogForm wd;
            wd = new DevExpress.Utils.WaitDialogForm("Vui lòng chờ trong giây lát.....", "Đang nạp dữ liệu");
            r = gridView1.GetDataRow(gridView1.FocusedRowHandle);
            if (r != null)
            {
                //neededit
                string _ID = r["Ma_HoNgheo"].ToString();
                Manager.frm_BaoCao frm = new Manager.frm_BaoCao(_ID);
                wd.Close();
                frm.ShowDialog();
            }
        }

        private void frm_BaoCao_search_Load(object sender, EventArgs e)
        {
            load_lk();
        }
    }
}
